let managerID = document.getElementById("managerID")
let managerFammilyName = document.getElementById("managerFammilyName")
let managerPassword = document.getElementById("managerPassword")
let managerEmail = document.getElementById("managerEmail")
let managerSignUpTime = document.getElementById("managerSignUpTime")
let managerGivenName = document.getElementById("managerGivenName")
window.addEventListener("load", (event) => {
    $.post("/manager/catManagerAccount",
        null,
        function (res) {
            if (res.status == "3001") {
                document.location = "/public/html/home.html"
            }
            else {
                managerID.value=res.data[0].id
                managerPassword.value=res.data[0].password
                managerGivenName.value=res.data[0].given_name
                let date = new Date(res.data[0].sign_up_time*1000).toLocaleString()
                managerSignUpTime.value=date
                managerFammilyName.value=res.data[0].fammily_name
                managerEmail.value=res.data[0].email
            }

        }, "json");

})
document.getElementById("managerAccount").addEventListener("click",(event => {
    let parameter = {
        "id":managerID.value,
        "fammily_name": managerFammilyName.value,
        "given_name": managerGivenName.value,
        "email": managerEmail.value,
        "password": managerPassword.value
    }
    $.post("/manager/modifyManagerAccount",
        parameter
        ,
        function (res) {
            if (res.status == "3001") {
                document.location = "/public/html/home.html"
            }
            else {
              alert(res.message)
                Cookies.set('username',userFammilyName.value.toString()+userGivenName.value.toString(),{ expires: 1 })
                location.reload()
            }

        }, "json");


}))